package online.longzipeng.cinemasys.controller;


import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import online.longzipeng.cinemasys.common.annotion.NeedPermissions;
import online.longzipeng.cinemasys.common.exception.AppException;
import online.longzipeng.cinemasys.common.result.ResponseEnum;
import online.longzipeng.cinemasys.common.result.Result;
import online.longzipeng.cinemasys.dto.customer.CustomerLoginResponseDTO;
import online.longzipeng.cinemasys.entity.Customer;
import online.longzipeng.cinemasys.service.CustomerService;
import online.longzipeng.cinemasys.vo.customer.CustomerChangePasswordVO;
import online.longzipeng.cinemasys.vo.customer.CustomerLoginVO;
import online.longzipeng.cinemasys.vo.customer.CustomerSaveVO;
import online.longzipeng.cinemasys.vo.customer.CustomerUpdateVO;
import online.longzipeng.cinemasys.vo.sysuser.SysUserChangePasswordVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 *  客户前端控制器
 * </p>
 *
 * @author lzp
 * @since 2021-04-08
 */
@RestController
@RequestMapping("/customer")
public class CustomerController {

    @Autowired
    CustomerService customerService;

    @PostMapping("/login")
    @ApiOperation("客户登录")
    public Result login(@RequestBody CustomerLoginVO customerLoginVO, HttpServletRequest httpServletRequest){
        CustomerLoginResponseDTO customerLoginResponseDTO = customerService.login(customerLoginVO,httpServletRequest);
        return Result.success(customerLoginResponseDTO);
    }

    @PostMapping("/save")
    @ApiOperation("新增客户")
    public Result save(@RequestBody CustomerSaveVO customerSaveVO){
        Customer customer = new Customer();
        BeanUtils.copyProperties(customerSaveVO,customer);
        customerService.add(customer);
        return Result.success("注册成功！！");
    }

    @PostMapping("/changePassword")
    @ApiOperation("修改用户密码")
    public Result changePassword(@RequestBody CustomerChangePasswordVO customerChangePasswordVO){
        customerService.changePassword(customerChangePasswordVO);
        return Result.success();
    }

}
